<?php
class InitAclController extends AppController
{
 var $name = 'InitAcl';
 var $components = array('Acl');
 var $uses=null;
 var $Aro=null;
 var $Aco=null;
    function setupAcl() 
  { 
    $aro = new aro(); 
    $aro->query("TRUNCATE TABLE `aros`");
    $aro->query("TRUNCATE TABLE `acos`");
    $aro->query("TRUNCATE TABLE `aros_acos`");
 
 
 
/* Add Public group */
    $aro->create(); 
    $aro->save(array( 
      'model'=>'Group', 
      'foreign_key'=>1, 
      'parent_id'=>null, 
      'alias'=>'Public')); 
 
 
 
/* Add Admin group */
    $aro->create(); 
    $aro->save(array( 
      'model'=>'Group', 
      'foreign_key'=>2, 
      'parent_id'=>1, 
      'alias'=>'Admin')); 
 
 
 
/* Add User group */
    $aro->create(); 
    $aro->save(array( 
      'model'=>'Group', 
      'foreign_key'=>3, 
      'parent_id'=>1, 
      'alias'=>'User')); 
 
/* Add admin1 user to Admin group */
    $aro->create(); 
    $aro->save(array( 
      'model'=>'User', 
      'foreign_key'=>1, 
      'parent_id'=>2, 
      'alias'=>'admin1'));      
 
 
/* Add User2 user to User group */
    $aro->create(); 
    $aro->save(array( 
      'model'=>'User', 
      'foreign_key'=>2, 
      'parent_id'=>3, 
      'alias'=>'user2'));   
 
 
      /* ACO */      
    $aco = new Aco(); 
    $aco->create(); 
    $aco->save(array( 
       'model'=>'', 
       'foreign_key'=>null, 
       'parent_id'=>null, 
       'alias'=>'ROOT')); 
 
    $aco->create();
    $aco->save(array( 
       'model'=>null, 
       'foreign_key'=>null, 
       'parent_id'=>1, 
       'alias'=>'posts')); 
 
 
    $aco->create(); 
    $aco->save(array( 
       'model'=>'MMovie', 
       'foreign_key'=>null, 
       'parent_id'=>1, 
       'alias'=>'admins'));
 
    $aco->create(); 
    $aco->save(array( 
       'model'=>'User', 
       'foreign_key'=>null, 
       'parent_id'=>1, 
       'alias'=>'users'));
 
    // Rules
   $this->Acl->deny('Public', 'ROOT');    // uzdraudziame visiems viska.
   $this->Acl->allow('Public', 'posts/index'); // leidziame visiems posts index veiksma atlitki   
 
   $this->Acl->allow('Public', 'posts/fullpost');   // leidziame visiems posts fullpost veiksma atlitki
 
   $this->Acl->allow('Public', 'users/login');    // leidziame visiems users login veiksma atlitki
 
   $this->Acl->allow('Public', 'users/register');   // leidziame visiems users register veiksma atlitki
   $this->Acl->allow('User', 'users');        // leidziame user grupei visus users veiksmus atlitki  
   $this->Acl->deny('User', 'users/login'); // uzdraudziame User grupei pasiekti login veiksma (tai reiskia jog prisijunge User grupes nariai negales eiti i login)    
 
   $this->Acl->deny('User', 'users/register'); // uzdraudziame User grupei pasiekti register veiksma
 
   $this->Acl->allow('User', 'posts');        // leidziame user grupei visus posts veiksmus atlitki
   $this->Acl->allow('Admin', 'users');   // leidziame admin grupei visus users veiksmus atlikti   
 
   $this->Acl->deny('Admin', 'users/login'); // uzdraudziame Admin grupei pasiekti login veiksma (tai reiskia jog prisijunge Admin grupes nariai negales eiti i login)    
 
   $this->Acl->deny('Admin', 'users/register'); // uzdraudziame Admin grupei pasiekti register veiksma
   $this->Acl->allow('Admin', 'posts'); // leidziame admin grupei visus posts veiksmus atlikti     
 
   $this->Acl->allow('Admin', 'admins'); // leidziame admin grupei visus admins veiksmus atlikti   
  echo "done";
  $this->autoRender = false;
   }
} 
?>